<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.lmpop.trade.shopcart.*"%>
<%@page import="com.lmpop.trade.ts_categoryattr.*"%>
<%@page import="com.lmpop.frame.util.Config"%>
<%@page import="com.lmpop.createIndex.search.*"%>
<%@page import="java.text.DecimalFormat"%>
<%@page import="com.lmpop.trade.ti_gift.Ti_giftInfo"%>
<%
	request.setCharacterEncoding("UTF-8");
	DecimalFormat  df  = new DecimalFormat("0.00");
	
	
	String info_state = "e";
	Map comMap = new Hashtable();
	comMap.put("info_state", info_state);
	AttachIndexFiles attachIndex = new AttachIndexFiles();
	GoodsIndexFiles goodsIndex = new GoodsIndexFiles();
	CompanyIndexFiles comIndex = new CompanyIndexFiles();
	CategoryattrIndexFiles attrIndex = new CategoryattrIndexFiles();
	WholesaleIndexFiles wholesaleIndex = new WholesaleIndexFiles();
	List goodsList = goodsIndex.getGoodsInfo(comMap);
	
	Config configa = new Config();
	configa.init();
	String goodsrootpath = configa.getString("goods_article_path");
	String custrootpath = configa.getString("company_shop_path");
 
	String noimg_path = "/templets/html/shop/images/zt.jpg";

	Hashtable<String ,Hashtable<String ,Goods>> cartMap = null;
	CartServices shopcart = null;
	int listsize =0;
	if(session.getAttribute("shoppingCart") != null) {
	  	shopcart = (CartServices) session.getAttribute("shoppingCart");
		cartMap = shopcart.getCartMap();
	} 
	if(cartMap != null && cartMap.size() > 0){
		listsize = cartMap.size();
	}

	float totalPrice = 0;
	float offerPrice=0;
	int totalGoodsCount = 0;
	int totalIntegralNum = 0;
	String giftInfos="";
	String discount_ids="";
	String ordergift="";
	int offer_type=0;
	int session_custlevel=0;
	  if( session.getAttribute("member_level") != null ){
			session_custlevel = Integer.parseInt(session.getAttribute("member_level").toString().trim());
		}
	if(shopcart != null){
		giftInfos=shopcart.getAllItemsGifts();
		totalPrice = shopcart.getAllItemsPrice();
		ordergift=shopcart.getGift_ids();
		offer_type=shopcart.getOffer_type();
		offerPrice=shopcart.getAllItemsOfferPrice(session_custlevel);
		totalGoodsCount = shopcart.getAllItemsCount();
		totalIntegralNum = shopcart.getAllItemsIntegralNum();
		discount_ids=shopcart.getAllItemsDiscountids();
	}	
	
	Ti_giftInfo ti_giftInfo=new Ti_giftInfo();
	StringBuffer discountids=new StringBuffer();
	
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<HEAD>
		<TITLE>购物车</TITLE>
		<META http-equiv=Content-Type content="text/html; charset=utf-8">
		<LINK href="/templets/html/shop/css/mycart.css" type=text/css
			rel=stylesheet>
		<LINK href="/templets/html/shop/css/tbsp.css" rel=stylesheet>
		<script type="text/javascript" src="/js/jquery-1.4.2.min.js"></script>
		<script type="text/javascript" src="ShopCart.js"></script>
		<script type="text/javascript"
			src="/js/thickbox/thickbox.js"></script>
		<link rel="stylesheet" href="/js/thickbox/thickbox.css"
			type="text/css" media="screen" />
		<link rel="stylesheet" rev="stylesheet"
			href="/templets/html/shop/css/main_right.css" type="text/css" />
	<BODY>
		<DIV id=cart>

			<table width="100%" border="0" cellspacing="0" cellpadding="0" class="f-right">
				<tr>

					<td>
						<table width="100%" border="0" cellpadding="0" cellspacing="0" class="table_main">

							<tr>

								<th width="5%" height="40" align="center">
									<img src="/program/member/index/images/icon1.gif">
								</th>

								<th width="85%">
									<h3>
										我的购物车
									</h3>
								</th>

								<th width="10%">
								</th>

							</tr>

						</table>
						<TABLE class="table_list" id=J_CartEnable cellSpacing=0 
							cellPadding=0 height=40>
							<COLGROUP vAlign=left>
								<COL width=62>
								<COL width=150>
								<COL width=70>
								<COL width=70>
								<COL width=100>
								<COL width=105>
								<COL width=116>
								<COL width=56>
								<COL width=100>
							</COLGROUP>
							<THEAD>
								<TR bgcolor="#F0F0F0">
									<th width="120" height="40">
										<input type="checkbox" name="selectAllItems"
											id="selectAllItems" onclick="selectAllItems();">
											全选 
									</th>
									<th width="300" colspan="2" >
										商品名称
									</th>
									<th>
										属性
									</th>
									<th>
										单价
									</th>
								
									<th>
										数量
									</th>
									<th align="center">
										小计
									</th>
									<th width="100">
										购物类型
									</td>
									<th>
										操作
									</th>
									<input type="hidden" name="listsize" id="listsize"
										value="<%=listsize%>" />
								</TR>
							</THEAD>
								<%
	    	if (cartMap != null && cartMap.size() > 0){
  		  Set cartSet = cartMap.entrySet();
  		  Iterator cartIterator = cartSet.iterator();
  		  int i = 0;

		  
		  %>
							<%
		  
  		  while (cartIterator.hasNext()) {
				++i;
			Map.Entry entry = (Map.Entry)cartIterator.next();
			String cust_id = entry.getKey().toString();      			
           Hashtable<String, Goods> goodsMap = cartMap.get(cust_id);
		   Map companyMap = comIndex.getCustNameById(cust_id);
		   String sc_cust_name = "",sc_shop_name="";
		   if(companyMap.get("cust_name")!=null) sc_cust_name = companyMap.get("cust_name").toString();
		   if(companyMap.get("cust_name")!=null) sc_shop_name = companyMap.get("cust_name").toString();

			Set goodsSet = goodsMap.entrySet();
  			Iterator goodsIterator = goodsSet.iterator();
			int listsizei = goodsMap.size();
		String custUrl = custrootpath + cust_id + "/index.html";
		%>
							<TBODY>
								
								<%   int j=0;
	List list=null;
	Map temp=null;
       while(goodsIterator.hasNext()){
          ++j;
      	  Map.Entry goodsentry = (Map.Entry)goodsIterator.next();
          String goods_random_id = goodsentry.getKey().toString();
		  String goods_id = goods_random_id.split("\\/")[0];
          Goods goodsInstance = goodsMap.get(goods_random_id);
		  
			String goods_name = "";
			String goods_props = "";
			//String goods_id="";
			String type = "";
			String type_id="";
			float shop_price = 0;
			float vip_price = 0;
			int buy_num = 0;
			int goods_IntegralNum = 0;
			float goods_subtotal = 0;
			String attr_str = "";
			String in_date = "";
			int goods_stock = 0;
			int goods_singel_IntegralNum = 0;
			float goods_singel_price = 0f;
			String gift_id="";
			String discount_id="";
			float discount=100;
			Map ginfoMap = goodsIndex.getOneGoods(goods_id,"goods");
			if (ginfoMap.get("goods_name")==null) ginfoMap = goodsIndex.getOneGoods(goods_id,"_shopgoods");
			
			if(ginfoMap.get("goods_name")!=null && !ginfoMap.get("goods_name").toString().equals("")) goods_name = ginfoMap.get("goods_name").toString();
			if(ginfoMap.get("in_date")!=null && !ginfoMap.get("in_date").toString().equals("")) in_date = ginfoMap.get("in_date").toString();
			if(ginfoMap.get("send_inter")!=null && !ginfoMap.get("send_inter").toString().equals("")) goods_singel_IntegralNum = Integer.valueOf(ginfoMap.get("send_inter").toString());
			if(ginfoMap.get("sale_price")!=null && !ginfoMap.get("sale_price").toString().equals("")) goods_singel_price = Float.valueOf(ginfoMap.get("sale_price").toString());
			if(ginfoMap.get("stock_num")!=null && !ginfoMap.get("stock_num").toString().equals("")) goods_stock = Integer.valueOf(ginfoMap.get("stock_num").toString());
			if(ginfoMap.get("discount_id")!=null && !ginfoMap.get("discount_id").toString().equals("")) discount_id = ginfoMap.get("discount_id").toString();
		
			if(in_date.length()>=8){
				String yeard = in_date.substring(0,4);
				String monthd = in_date.substring(4,6);
				String dayd = in_date.substring(6,8);
				in_date = yeard+"-"+monthd+"-"+dayd;
			}


			goods_subtotal = goodsInstance.getTotalShopPrice();

			goods_IntegralNum = goodsInstance.getTotalIntegralNum();
			float offer_price=0;
			if(goodsInstance != null){
				goods_props = goodsInstance.getGoods_props();
				shop_price = goodsInstance.getShop_price();
				vip_price = goodsInstance.getVip_price();
				buy_num = goodsInstance.getBuy_num();
				type = goodsInstance.getType();
				type_id = goodsInstance.getType_id();
				attr_str = attrIndex.getCatAttrFromStr(goods_props);
				offer_price=goodsInstance.getOffer_price();
				discount= (offer_price/shop_price)*100;
				discount_id=goodsInstance.getDiscount_id();
				if(discount_id!=null&&!"".equals(discount_id))
					discountids.append(discount_id+",");
				gift_id=goodsInstance.getGift_id();
				if(gift_id!=null&&!"".equals(gift_id)){
					list=ti_giftInfo.getListByPk(gift_id);
					if(list!=null&&list.size()>0){
						temp=(Hashtable)list.get(0);
						gift_id=temp.get("gift_name").toString();
					}
				}
			}
			String buy_type = "";
			if(type.equals("0")){
				buy_type = "普通购物";
			}else if(type.equals("1")){
				buy_type = "批发";
			}else if(type.equals("2")){
				buy_type = "拍卖";
			}else if(type.equals("3")){
				buy_type = "团购";
			}
			 String img_path =  attachIndex.getFilepathById(goods_id);
			 String goodsUrl = "";
            
            if(img_path.equals(""))
            {
                 img_path ="/program/admin/images/cpwu.gif";
            }     
			if (cust_id.equals("100000000000000"))
			{
				goodsUrl = goodsrootpath + in_date  + "/" + goods_id + ".html" ;
			}
		else
			{
				goodsUrl = custrootpath+cust_id+"/goods/"+ in_date + "/" + goods_id + ".html";
			}
			
  %>
								<TR class="uncod xcard selected" id="goods_<%=goods_random_id%>"
									name="goods_<%=goods_random_id%>">
									<input type="hidden" name="listsize<%=i%>" id="listsize<%=i%>"
											value="<%=listsizei%>"> 
									<td width="60" height="30"> 
										<INPUT class=J_CheckBoxItem type=checkbox
											name="MyCartGoodsChecks" id="<%=i%>checkone<%=j%>"
											value="<%=goods_random_id%>" onclick="selectSingle();">
									</td>
									<td width="350" colspan="2">
										<a href="<%=goodsUrl%>" target="_blank"><img src="<%=img_path%>"
												border="0" width="46" height="49" /> </a>
										<DIV class=props>
											<SPAN class=xcard-icon></SPAN>
											<SPAN><a href="<%=goodsUrl%>" target="_blank"><%=goods_name%></a> </SPAN>
											<input name="goods_attr" id="goods_attr" type="hidden"
												value="<%=goods_props%>" />
											<input type="hidden"
												name="goodsIntegral_<%=goods_random_id%>"
												id="goodsIntegral_<%=goods_random_id%>"
												value="<%=goods_singel_IntegralNum%>">
										</DIV>
									</td>
									<td width="180">
										<%if(type.equals("0")){%>
										<a
											href="/program/member/personal/buycart/ajaxShowCatAtrr.jsp?cust_id=<%=cust_id%>&amp;goods_id=<%=goods_random_id%>&amp;goods_props=<%=goods_props%>&amp;TB_iframe=true&amp;height=300&amp;width=500&amp;KeepThis=true"
											class="thickbox"> <span
											id="goods_attr_id_<%=goods_random_id%>"
											name="goods_attr_id_<%=goods_random_id%>"><%=attr_str%></span>
										</a>
										<%}else{%>
										<span id="goods_attr_id_<%=goods_random_id%>"
											name="goods_attr_id_<%=goods_random_id%>"><%=attr_str%></span>
										<%}%>
									</td>
									<td width="150">
										￥
										<span name="shop_price_<%=goods_random_id%>"
											id="shop_price_<%=goods_random_id%>"><%=df.format(shop_price)%>
										</span>
									</td>
									<td width="70">
										<input type="text" 
											name="buy_num_<%=goods_random_id%>"
											id="buy_num_<%=goods_random_id%>" value="<%=buy_num%>"
											style="width: 26px;" maxlength="3" onkeyup='javascript:if((!/^[1-9][0-9]*$/.test(this.value))||(checkGoodsStock("<%=goods_id%>") > <%=goods_stock%>)){this.value="1";ShopCartOperating("<%=cust_id%>","<%=goods_random_id%>","2");}else{ShopCartOperating("<%=cust_id%>","<%=goods_random_id%>","2");}'>
									</td>

									<td width="120">
										￥<%=df.format(goods_subtotal)%>
									</td>
									<td width="120">
										<%=buy_type%>
									</td>
									<td width="80">
										<a href="####"
											onclick="ShopCartOperating('<%=cust_id%>','<%=goods_random_id%>','3');">删除</a>
									</td>

								</TR>
							</TBODY>
							<%
		} 
		}
  %>
							<TFOOT>
								<TR>
									<!-- <TD class=point-info colSpan=4></TD> -->
									<TD class=charge-info colSpan=9 height="40">
										<SPAN class=total-fee-info>商品总价(不含运费)： <EM class=total2><span
												name="totalPrice" class="totalPrice">￥<%=df.format(totalPrice)%>元</span>
										</EM> </SPAN>
										<SPAN class=total-fee-info>优惠价： <EM class=total2><span
												name="offerPrice" class="totalPrice">￥<%=df.format(offerPrice)%>元</span>
										</EM> </SPAN>
										<SPAN class=total-fee-info>礼品： <EM class=total2><span
												name="gift_ids" id="gift_ids"><%=giftInfos %></span> </EM> </SPAN>
									</TD>
								</TR>
								<TR>
									<TD class="go clearfix" colSpan=13 height="40">
										<input type="hidden" name="discount_ids" id="discount_ids"
											value="<%=discount_ids %>" />
										<input type="hidden" name="skip_type" id="skip_type" value="myBuyCart" />
										<input type="hidden" name="gift_ids" id="gift_ids"
											value="<%=giftInfos %>" />
										<input type="hidden" name="offer_type" id="offer_type"
											value="<%=offer_type %>" />
										<input type="hidden" name="ordergiftid" id="ordergiftid"
											value="<%=ordergift %>" />

										<SPAN><input class="button2" name="" type="submit"
												value="批量删除" onclick="delIndexInfo();">
										</SPAN>
										<!--<SPAN><input class="btn11" name="" type="submit" value="批量收藏"></SPAN>-->

										<DIV class="msg floatleft mg-left" style="DISPLAY: none"></DIV>
										<BUTTON class="button2"
											onclick="javascript:top.window.location.href='/templets/html/shop/jsp/confirm_order_address.jsp#hasaddress'">
											结 算
										</BUTTON>
									</TD>
								</TR>
							</TFOOT>
						</TABLE>
						<%}%>
  <div name="hiddenData" id="hiddenData" style="display:none">
</div>
<div name="hiddenAttrData" id="hiddenAttrData" style="display:none">
</div>
	 </DIV>
							</LI>
							</UL>
							</DIV>
	</BODY>
</html>
